home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / cagd_lib / cagdcsrf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  3.0 KB  |  79 lines

  1. /******************************************************************************
  2. * CagdCSrf.c - Constructa surface using a set of curves.                      *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Sep. 91.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /******************************************************************************
  10. * Constructs a surface using a set of curves. Curves are made to be          *
  11. * compatible and then each is substituted in the resulting surface as a row.  *
  12. *   Other direction order is at most the compatible curves order. If order is *
  13. * less than number of curves a knot vector is formed uniformly (open end).    *
  14. ******************************************************************************/
  15. CagdSrfStruct *CagdSrfFromCrvs(CagdCrvStruct *CrvList, int OtherOrder)
  16. {
  17.     CagdBType IsNotRational;
  18.     int i, j, NumCrvs, UOrder, VOrder, MaxCoord, Length;
  19.     CagdRType **SrfPoints;
  20.     CagdCrvStruct *Crv, **CrvVec;
  21.     CagdSrfStruct *Srf;
  22.  
  23.     /* Find out how many curves we have and put them in a linear vector.     */
  24.     /* Note the vector have a COPY of the curves so we can modify them.      */
  25.     for (NumCrvs = 0, Crv = CrvList;
  26.      Crv != NULL;
  27.      NumCrvs++, Crv = Crv -> Pnext);
  28.     CrvVec = (CagdCrvStruct **) IritMalloc(sizeof(CagdCrvStruct *) * NumCrvs);
  29.     for (i = 0, Crv = CrvList;
  30.      i < NumCrvs;
  31.      i++, Crv = Crv -> Pnext)
  32.     CrvVec[i] = CagdCrvCopy(Crv);
  33.  
  34.     /* Traverse vector in a O(n^2) fashion and make all curves compatible.   */
  35.     for (i = 0; i < NumCrvs - 1; i++)
  36.     for (j = i + 1; j < NumCrvs; j++)
  37.         CagdMakeCrvsCompatible(&CrvVec[i], &CrvVec[j], TRUE, TRUE);
  38.  
  39.     /* Construct the surface. All required information is now available.     */
  40.     UOrder = CrvVec[0] -> Order;
  41.     VOrder = MIN(NumCrvs, OtherOrder);
  42.     if (NumCrvs == VOrder && CrvVec[0] -> GType == CAGD_CBEZIER_TYPE) {
  43.         /* Allocate a bezier surface. */
  44.     Srf = BzrSrfNew(CrvVec[0] -> Length, NumCrvs, CrvVec[0] -> PType);
  45.     }
  46.     else {
  47.     /* Allocate a bspline surface. */
  48.     Srf = BspSrfNew(CrvVec[0] -> Length, NumCrvs, UOrder, VOrder,
  49.             CrvVec[0] -> PType);
  50.     IritFree((VoidPtr) Srf -> UKnotVector);
  51.     Srf -> UKnotVector = BspKnotCopy(CrvVec[0] -> KnotVector,
  52.                      CrvVec[0] -> Length + CrvVec[0] -> Order);
  53.     BspKnotUniformOpen(NumCrvs, VOrder, Srf -> VKnotVector);
  54.     }
  55.  
  56.     /* Substitute each curve as a row into the surface mesh and delete it. */
  57.     SrfPoints = Srf -> Points;
  58.     i = 0;
  59.     MaxCoord = CAGD_NUM_OF_PT_COORD(CrvVec[0] -> PType),
  60.     IsNotRational = !CAGD_IS_RATIONAL_CRV(CrvVec[0]);
  61.     Length = CrvVec[0] -> Length;
  62.  
  63.     for (j = 0; j < NumCrvs; j++) {
  64.     int k;
  65.     CagdRType **CrvPoints = CrvVec[j] -> Points;
  66.  
  67.         for (k = IsNotRational; k <= MaxCoord; k++)
  68.         CAGD_GEN_COPY(&SrfPoints[k][i], CrvPoints[k],
  69.               sizeof(CagdRType) * Length);
  70.  
  71.     CagdCrvFree(CrvVec[j]);
  72.     i += Length;
  73.     }
  74.  
  75.     IritFree((VoidPtr) CrvVec);
  76.  
  77.     return Srf;
  78. }
  79.